#ifndef RENDERMANAGER_H
#define RENDERMANAGER_H

#include <GameGlobals.h>
#include <string>
#include <list>
#include <map>

struct GraphicData;
struct RenderObject;
struct Transform;
struct ColorData;
class BaseObject;

const unsigned DEFAULT_RESERVED_GRAPHIC_SPACE = 64;

class RenderManager
{
	friend class ObjectManager;
	friend struct GraphicData;
	public:

		RenderManager();
		~RenderManager();

		truth CreateShaderObjects();

		void Render(std::vector<RenderObject*>& objects);
		void RenderObjects(std::vector<RenderObject*>& objects);
	
		GraphicData* LoadGfx(std::string filename);
		GraphicData* LoadGfxFromBMP(const std::string& filename);

		RenderObject* CreateRenderObject(Transform* t, GraphicData* g);

	private:

		truth CreateShader(const std::string& filename, unsigned handle);
		truth LoadShaderFile(const std::string& filename, char** out_shaderStrings);
		truth CompileShader(unsigned shaderHandle, char* shader_data);
		truth LinkShaders(unsigned program, unsigned vertex, unsigned fragment);

		void LoadColorDataForGfx(const std::string& filename, std::list<ColorData >& out_data);

		truth AddGfx( GraphicData* g, std::string filename );
		truth HasGfx( std::string filename );
		void AllocateGraphicSpace( unsigned size );
		void RemoveRenderObject( RenderObject* r );
		void RemoveRenderObject(unsigned i);

		std::vector<RenderObject*> renderObjects;

		std::map<std::string,unsigned> loadedGraphics;

		unsigned maxStorage;
		unsigned currentStorage;
		GraphicData** graphics;
		

		//shader data
		unsigned vertexShader;
		unsigned fragmentShader;
		unsigned basicProgram;
		
		unsigned glowShader;
		unsigned glowProgram;
};


#endif